﻿package net.wangit.view.tree;

import net.wangit.MapList;
import net.wangit.framework.config.DomainsSettings;
import net.wangit.jdbc.DB;
import net.wangit.jdbc.DBFactory;
import net.wangit.jdbc.JDBCException;
import net.wangit.support.TreeFactory;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class DatasourceTreeFactory extends TreeFactory {

	private static final Log log = LogFactory.getLog(DefaultTreeFactory.class);

	public DatasourceTreeFactory() {
	}

	public Tree createTree(String domain) {
		MapList list;
		try {
			DB db = DBFactory.getDB(DomainsSettings.getDatasource(domain));
			list = db.query(getConfig().getTreeId());
			return TreeUtil.getTree(list);
		} catch (JDBCException e) {
			log.error((new StringBuilder("could not create tree by ")).append(
					domain).append("/").append(getConfig().getTreeId())
					.toString(), e);
			return null;
		}
	}

}
